package com.zgl.schedule.orderprofit.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zgl.schedule.orderprofit.entity.OrderEntity;
import com.zgl.schedule.orderprofit.mapper.OrderMapper;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class ScheduleOrder {
    @Resource
    OrderMapper orderMapper;

    @Scheduled(cron="0/30 * * * *  ?")
    public void scheduleOrder(){
        QueryWrapper<OrderEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("delete_status",0);
        List<OrderEntity> orderEntityList= orderMapper.selectList(queryWrapper);
        for (OrderEntity item:orderEntityList) {
            double oldProfit = Double.valueOf(item.getProfit());
            double money = Double.valueOf(item.getGoodsPrice());
            double rate = Double.valueOf(item.getGoodsRate());
            double currenProfit= ((money+oldProfit)*rate)+oldProfit;
            String currenProfitStr=""+currenProfit;
            item.setProfit( String.format("%.2f", currenProfit));
            orderMapper.updateById(item);
            System.out.println("修改"+item+"订单的收益");
        }



    }
}
